Graphics3D 1024,768,32,2
SetBuffer BackBuffer()
HidePointer

;cam
Global ply = CreateCube()
ScaleEntity ply,.5,.5,.5
Global cam = CreateCamera(ply)
EntityType ply,1
PositionEntity cam,0,3,0
EntityAlpha ply,0
CameraRange cam,1,100000
;world
boden = CreatePlane()
boden2 = CreatePlane()
EntityType boden,2
EntityType boden2,2
bodentex = LoadTexture("textures\grid.png",2)
ScaleTexture bodentex,.5,.5
bodentex2 = LoadTexture("textures\brick.bmp")
EntityTexture boden,bodentex
EntityTexture boden2,bodentex2
alpha# = 0
alpha2# = 0
dark# = 0
EntityAlpha boden2,0
PositionEntity boden,0,-3,0
PositionEntity boden2,0,-3.99,0

Collisions 1,2,2,2
;!SKY
;Himmel erstellen
sky=CreateMesh()
skyface2=CreateSurface(sky,brush)
v02=AddVertex(skyface2,0,160,0)
v12=AddVertex(skyface2,-1000,-4,-1000)
v22=AddVertex(skyface2,-1000,-4,+1000)
v32=AddVertex(skyface2,+1000,-4,-1000)
v42=AddVertex(skyface2,+1000,-4,+1000)
VertexColor skyface2,v02,55+100,87+100,102+100
VertexColor skyface2,v12,129+100,129+100,129+100
VertexColor skyface2,v22,182+100,182+100,182+100
VertexColor skyface2,v32,121+100,121+100,121+100
VertexColor skyface2,v42,40+100,119+100,115+100
AddTriangle skyface2,v02,v22,v12
AddTriangle skyface2,v02,v42,v22
AddTriangle skyface2,v02,v32,v42
AddTriangle skyface2,v02,v12,v32
EntityFX sky,3

;!SKY2
;Himmel erstellen
sky=CreateMesh()
skyface=CreateSurface(sky,brush)
v0=AddVertex(skyface,0,160,0)
v1=AddVertex(skyface,-1000,-4,-1000)
v2=AddVertex(skyface,-1000,-4,+1000)
v3=AddVertex(skyface,+1000,-4,-1000)
v4=AddVertex(skyface,+1000,-4,+1000)
VertexColor skyface,v0,55+100,87+100,102+100
VertexColor skyface,v1,129+100,129+100,129+100
VertexColor skyface,v2,182+100,182+100,182+100
VertexColor skyface,v3,121+100,121+100,121+100
VertexColor skyface,v4,40+100,119+100,115+100
AddTriangle skyface,v0,v2,v1
AddTriangle skyface,v0,v4,v2
AddTriangle skyface,v0,v3,v4
AddTriangle skyface,v0,v1,v3
EntityFX sky,3
RotateEntity sky,180,0,0

Global yv#
;light
light = CreateLight(2)
PositionEntity light,0,50,0

ey# = EntityY(ply)
While Not KeyDown(1)
	yv# = EntityY(ply)-ey#
	ey# = EntityY(ply)
	
	CameraMovement()
	
	If alpha < 1 And alpha2 < 1 Then
		alpha# = alpha#+0.005
		dark = dark+0.25
		EntityAlpha boden,alpha#
		
		VertexColor skyface2,v02,55+100-dark,87+100-dark,102+100-dark
		VertexColor skyface2,v12,129+100-dark,129+100-dark,129+100-dark
		VertexColor skyface2,v22,182+100-dark,182+100-dark,182+100-dark
		VertexColor skyface2,v32,121+100-dark,121+100-dark,121+100-dark
		VertexColor skyface2,v42,40+100-dark,119+100-dark,115+100-dark
		
		VertexColor skyface,v0,55+100-dark,87+100-dark,102+100-dark
		VertexColor skyface,v1,129+100-dark,129+100-dark,129+100-dark
		VertexColor skyface,v2,182+100-dark,182+100-dark,182+100-dark
		VertexColor skyface,v3,121+100-dark,121+100-dark,121+100-dark
		VertexColor skyface,v4,40+100-dark,119+100-dark,115+100-dark
	ElseIf alpha > 1 And alpha < 2 And alpha2 < 1 Then
		alpha2# = alpha2#+0.005
		dark = dark+0.25
		EntityAlpha boden2,alpha2
		
		VertexColor skyface2,v02,55+100-dark,87+100-dark,102+100-dark
		VertexColor skyface2,v12,129+100-dark,129+100-dark,129+100-dark
		VertexColor skyface2,v22,182+100-dark,182+100-dark,182+100-dark
		VertexColor skyface2,v32,121+100-dark,121+100-dark,121+100-dark
		VertexColor skyface2,v42,40+100-dark,119+100-dark,115+100-dark
		
		VertexColor skyface,v0,55+100-dark,87+100-dark,102+100-dark
		VertexColor skyface,v1,129+100-dark,129+100-dark,129+100-dark
		VertexColor skyface,v2,182+100-dark,182+100-dark,182+100-dark
		VertexColor skyface,v3,121+100-dark,121+100-dark,121+100-dark
		VertexColor skyface,v4,40+100-dark,119+100-dark,115+100-dark
	ElseIf alpha2 > 1 And alpha2 < 2 And alpha > 0 Then
		alpha# = alpha#-0.005
		EntityAlpha boden,alpha#
	EndIf
	
	TranslateEntity ply,0,yv#-.005,0
	RenderWorld
	UpdateWorld
	Text 0,0,yv
	Flip
Wend


;Cam_Functions
Function CameraMovement()
		mx# = Curve(MouseX()-GraphicsWidth()/2,mx,6)
		my# = Curve(MouseY()-GraphicsHeight()/2,my,6)
		RotateEntity ply,0,EntityYaw(ply)-mx*3,0
		RotateEntity cam,EntityPitch(cam)+my*3,0,0
		MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
	
	move# = Curve((KeyDown(17)-KeyDown(31)),move,20)
	strafe# = Curve((KeyDown(32)-KeyDown(30)),strafe,20)
	If KeyDown(57) And yv# = 0 Then yv# = .15
	MoveEntity ply,strafe*3,0,move*3
	
End Function

Function Curve#(newvalue#,oldvalue#,increments#)
	Local sign,slip#
	sign=Sgn(oldvalue-newvalue)
	slip#=(oldvalue-newvalue)/increments
	If Abs(slip)<ml slip=ml*Sgn(slip)
		oldvalue=oldvalue-slip
		If sign<>Sgn(oldvalue-newvalue) Return newvalue
			Return oldvalue
End Function


;~IDEal Editor Parameters:
;~C#Blitz3D